package whf.shop.service;

import java.util.List;

import whf.framework.exception.FindException;
import whf.framework.exception.ServiceNotFoundException;
import whf.framework.security.entity.User;
import whf.framework.util.BeanFactory;
import whf.shop.dao.MemberDAO;
import whf.shop.entity.Member;

/**
 * 服务对象具体实现，委托相应的dao对象实现相关操作
 * 
 * @author wanghaifeng
 * @email king@126.com
 * @modify 2007-01-11
 */
public class MemberServiceImp extends whf.framework.service.ServiceImp<Member>
		implements MemberService {

	private MemberDAO memberDAO;

	public void setMemberDAO(MemberDAO memberDAO) {
		this.memberDAO = memberDAO;
	}

	public static MemberService getMemberService()
			throws ServiceNotFoundException {
		return (MemberService) BeanFactory.getService(MemberServiceImp.class);
	}

	/* (non-Javadoc)
	 * @see whf.shop.service.MemberService#findByUser(whf.framework.auth.entity.User)
	 */
	public Member findByUser(User user) throws FindException {
		if(user == null) return null;
		List<Member> list = this.memberDAO.find("t.user=?", user);
		if(list.size() > 0){
			return (Member)list.get(0);
		} else {
			return null;
		}
	}

	/* (non-Javadoc)
	 * @see whf.shop.service.MemberService#findByLogin(java.lang.String)
	 */
	public Member findByLogin(String login) throws FindException {
		List<Member> list = this.memberDAO.find("t.login=?", login);
		if(list.size() > 0){
			return (Member)list.get(0);
		} else {
			return null;
		}
	}

}